<template>
  <div class="community-analysis-container">
    <h2 class="page-title">社区互动数据分析</h2>
    
    <!-- 筛选栏 -->
    <div class="filter-bar">
      <el-date-picker
        v-model="dateRange"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="YYYY-MM-DD"
        @change="handleDateChange"
      />
    </div>

    <!-- 核心指标卡片 -->
    <div class="community-core-metrics">
      <div class="metric-card">
        <div class="metric-title">总发帖量</div>
        <div class="metric-value">{{ formatNumber(metrics.totalPosts) }}</div>
        <div class="metric-subtitle" v-if="dateRange.length > 0">
          当前筛选: {{ dateRange[0] }} 至 {{ dateRange[1] }}
        </div>
      </div>

      <div class="metric-card">
        <div class="metric-title">总评论数</div>
        <div class="metric-value">{{ formatNumber(metrics.totalComments) }}</div>
      </div>

      <div class="metric-card">
        <div class="metric-title">总点赞数</div>
        <div class="metric-value">{{ formatNumber(metrics.totalLikes) }}</div>
      </div>

      <div class="metric-card">
        <div class="metric-title">总收藏数</div>
        <div class="metric-value">{{ formatNumber(metrics.totalFavorites) }}</div>
      </div>
    </div>

    <!-- 导航条 -->
    <div class="analysis-nav">
      <el-tabs v-model="activeTab" @tab-change="handleTabChange">
        <el-tab-pane label="互动趋势" name="trend"></el-tab-pane>
        <el-tab-pane label="热门分析" name="hot"></el-tab-pane>
        <el-tab-pane label="热门内容" name="content"></el-tab-pane>
      </el-tabs>
    </div>

    <!-- 图表展示区域 -->
    <div class="chart-container">
      <!-- 互动趋势图表 -->
      <div class="chart-area" v-show="activeTab === 'trend'">
        <h3>社区互动趋势</h3>
        <div id="trendChart" style="width: 100%; height: 400px;"></div>
        
        <h3 style="margin-top: 30px;">帖子类型分布</h3>
        <div id="typeChart" style="width: 100%; height: 400px;"></div>
      </div>

      <!-- 热门分析图表 -->
      <div class="chart-area" v-show="activeTab === 'hot'">
        <h3>热门分析</h3>
        <div class="hot-analysis-content">
          <!-- 活跃用户排行 -->
          <div class="hot-analysis-section">
            <h4>活跃用户排行</h4>
            <el-table 
              :data="hotAnalysis.mostActiveUsers" 
              style="width: 100%" 
              border
              height="400"
              v-loading="hotAnalysis.loading"
              @sort-change="handleSortChange"
              :default-sort="{ prop: 'totalActivity', order: 'descending' }"
            >
              <el-table-column prop="name" label="用户名" width="180" />
              <el-table-column prop="postCount" label="发帖数" width="100" sortable />
              <el-table-column prop="commentCount" label="评论数" width="100" sortable />
              <el-table-column prop="likeCount" label="点赞数" width="100" sortable />
              <el-table-column prop="favoriteCount" label="收藏数" width="100" sortable />
              <el-table-column prop="totalActivity" label="总活跃度" width="120" sortable>
                <template #default="{row}">
                  <el-tag :type="getActivityType(row.totalActivity)">
                    {{ row.totalActivity }}
                  </el-tag>
                </template>
              </el-table-column>
            </el-table>
            <div class="pagination-container">
              <el-pagination
                v-model:current-page="hotAnalysis.pagination.currentPage"
                v-model:page-size="hotAnalysis.pagination.pageSize"
                :page-sizes="[5, 10, 20, 50]"
                :total="hotAnalysis.pagination.total"
                :background="true"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handlePageSizeChange"
                @current-change="handlePageChange"
              />
            </div>
          </div>

          <!-- 互动趋势 -->
          <div class="hot-analysis-section">
            <h4>互动高峰时段</h4>
            <div class="peak-hours">
              <el-tag 
                v-for="(hour, index) in hotAnalysis.interactionTrend.peakHours" 
                :key="index"
                type="success"
                size="large"
                class="peak-hour-tag"
              >
                {{ hour }}
              </el-tag>
            </div>
            
            <h4 style="margin-top: 20px;">每周互动模式</h4>
            <div id="weeklyPatternChart" style="width: 100%; height: 300px;"></div>
          </div>

          <!-- 热门标签 -->
          <div class="hot-analysis-section">
            <h4>热门标签</h4>
            <div class="popular-tags">
              <el-tag 
                v-for="tag in hotAnalysis.popularTags" 
                :key="tag.tag"
                :type="getTagType(tag.count)"
                size="large"
                class="popular-tag"
              >
                {{ tag.tag }} ({{ tag.count }})
              </el-tag>
            </div>
          </div>
        </div>
      </div>

      <!-- 热门内容图表 -->
      <div class="chart-area" v-show="activeTab === 'content'">
        <h3>热门内容</h3>
        <div class="hot-content-container">
          <!-- 热门内容筛选 -->
          <div class="hot-content-filter">
            <el-radio-group v-model="hotContent.timeRange" @change="handleTimeRangeChange">
              <el-radio-button label="all">全部</el-radio-button>
              <el-radio-button label="week">本周</el-radio-button>
              <el-radio-button label="month">本月</el-radio-button>
            </el-radio-group>
          </div>
          
          <!-- 热门内容列表 -->
          <div class="hot-content-list">
            <el-table 
              :data="hotContent.posts" 
              style="width: 100%" 
              border
              v-loading="hotContent.loading"
              :default-sort="{ prop: 'hotScore', order: 'descending' }"
            >
              <el-table-column prop="title" label="标题" width="200">
                <template #default="{row}">
                  <el-link type="primary" :underline="false">{{ row.title }}</el-link>
                </template>
              </el-table-column>
              <el-table-column prop="content" label="内容" width="300">
                <template #default="{row}">
                  <div class="post-content">{{ row.content }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="tag" label="类型" width="120" />
              <el-table-column prop="viewCount" label="浏览量" width="100" sortable />
              <el-table-column label="评论数" width="100" sortable>
                <template #default="{row}">
                  {{ row.commentCount || 0 }}
                </template>
              </el-table-column>
              <el-table-column label="点赞数" width="100" sortable>
                <template #default="{row}">
                  {{ row.likeCount || 0 }}
                </template>
              </el-table-column>
              <el-table-column label="收藏数" width="100" sortable>
                <template #default="{row}">
                  {{ row.favoriteCount || 0 }}
                </template>
              </el-table-column>
              <el-table-column label="热度分数" width="120" sortable>
                <template #default="{row}">
                  <el-tag :type="getScoreType(row.hotScore)">
                    {{ row.hotScore?.toFixed(2) || '0.00' }}
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column prop="createdAt" label="发布时间" width="180">
                <template #default="{row}">
                  {{ formatDate(row.createdAt) }}
                </template>
              </el-table-column>
            </el-table>
            <div class="pagination-container">
              <el-pagination
                v-model:current-page="hotContent.pagination.currentPage"
                v-model:page-size="hotContent.pagination.pageSize"
                :page-sizes="[5, 10, 20, 50]"
                :total="hotContent.pagination.total"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handleHotContentPageSizeChange"
                @current-change="handleHotContentPageChange"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, onMounted, nextTick } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
import * as echarts from 'echarts'

export default {
  name: 'CommunityAnalysis',
  setup() {
    // ==================== 状态管理 ====================
    const dateRange = ref([])
    const selectedType = ref('all')
    const searchText = ref('')
    const activeTab = ref('trend')

    // 核心指标数据
    const metrics = ref({
      totalPosts: 0,
      totalComments: 0,
      totalLikes: 0,
      totalFavorites: 0
    })

    // 热门分析数据
    const hotAnalysis = ref({
      mostActiveUsers: [],
      interactionTrend: {
        peakHours: [],
        weeklyPattern: []
      },
      popularTags: [],
      loading: false,
      pagination: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      },
      sortProp: 'totalActivity',  // 默认按活跃度排序
      sortOrder: 'descending'     // 默认降序排列
    })

    // 热门内容数据
    const hotContent = ref({
      posts: [],
      timeRange: 'week',
      loading: false,
      pagination: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      }
    })

    // 图表实例
    let trendChart = null
    let typeChart = null
    let weeklyPatternChart = null

    // ==================== 工具方法 ====================
    const formatNumber = (num) => {
      return num?.toLocaleString() ?? '0'
    }

    const formatDate = (dateStr) => {
      if (!dateStr) return ''
      const date = new Date(dateStr)
      return date.toLocaleString()
    }

    const getTagType = (count) => {
      if (count > 30) return 'danger'
      if (count > 20) return 'warning'
      if (count > 10) return 'primary'
      return 'info'
    }

    const getScoreType = (score) => {
      if (!score) return 'info'
      if (score > 80) return 'danger'
      if (score > 60) return 'warning'
      if (score > 40) return 'success'
      if (score > 20) return 'primary'
      return 'info'
    }

    const getActivityType = (activity) => {
      if (activity > 50) return 'danger'
      if (activity > 30) return 'warning'
      if (activity > 15) return 'success'
      if (activity > 5) return 'primary'
      return 'info'
    }

    // ==================== 事件处理 ====================
    const handleDateChange = (dates) => {
      if (dates && dates.length === 2) {
        fetchData()
      } else {
        dateRange.value = []
        fetchData()
      }
    }

    const handleTabChange = (tabName) => {
      activeTab.value = tabName
      nextTick(() => {
        if (tabName === 'trend') {
          trendChart?.resize()
          typeChart?.resize()
          fetchChartData()
        } else if (tabName === 'hot') {
          weeklyPatternChart?.resize()
          fetchHotAnalysis()
        } else if (tabName === 'content') {
          fetchHotContent()
        }
      })
    }

    const handleSortChange = ({ prop, order }) => {
      hotAnalysis.value.sortProp = prop || 'totalActivity'
      hotAnalysis.value.sortOrder = order || 'descending'
      fetchHotAnalysis()
    }

    const handleTimeRangeChange = () => {
      hotContent.value.pagination.currentPage = 1
      fetchHotContent()
    }

    // ==================== 数据获取 ====================
    // 获取核心指标数据
    const fetchCoreMetrics = async () => {
      try {
        await Promise.all([
          fetchTotalPosts(),
          fetchTotalComments(),
          fetchTotalLikes(),
          fetchTotalFavorites()
        ])
      } catch (error) {
        console.error('获取核心指标失败:', error)
        ElMessage.error('获取核心指标数据失败')
      }
    }

    const fetchTotalPosts = async () => {
      try {
        let url = '/post/total-count'
        if (dateRange.value && dateRange.value.length === 2) {
          const [startDate, endDate] = dateRange.value
          url = `/post/count-by-date?startDate=${startDate}&endDate=${endDate}`
        }
        const response = await axios.get(url)
        metrics.value.totalPosts = response.data.data || response.data
      } catch (error) {
        console.error('获取发帖量失败:', error)
        throw error
      }
    }

    const fetchTotalComments = async () => {
      try {
        let url = '/post-comment/total-count'
        if (dateRange.value?.length === 2) {
          const [startDate, endDate] = dateRange.value
          url = `/post-comment/count-by-date?startDate=${startDate}&endDate=${endDate}`
        }
        const response = await axios.get(url)
        metrics.value.totalComments = response.data.data || response.data
      } catch (error) {
        console.error('获取评论数失败:', error)
        throw error
      }
    }

    const fetchTotalLikes = async () => {
      try {
        let url = '/post-like/total-count'
        if (dateRange.value && dateRange.value.length === 2) {
          const [startDate, endDate] = dateRange.value
          url = `/post-like/count-by-date?startDate=${startDate}&endDate=${endDate}`
        }
        const response = await axios.get(url)
        metrics.value.totalLikes = response.data.data || response.data
      } catch (error) {
        console.error('获取点赞数失败:', error)
        throw error
      }
    }

    const fetchTotalFavorites = async () => {
      try {
        let url = '/post-favorite/total-count'
        if (dateRange.value && dateRange.value.length === 2) {
          const [startDate, endDate] = dateRange.value
          url = `/post-favorite/count-by-date?startDate=${startDate}&endDate=${endDate}`
        }
        const response = await axios.get(url)
        metrics.value.totalFavorites = response.data.data || response.data
      } catch (error) {
        console.error('获取收藏数失败:', error)
        throw error
      }
    }

    // 获取热门分析数据
    const fetchHotAnalysis = async () => {
      hotAnalysis.value.loading = true
      try {
        const params = {
          page: hotAnalysis.value.pagination.currentPage,
          pageSize: hotAnalysis.value.pagination.pageSize,
          sort: hotAnalysis.value.sortProp,
          order: hotAnalysis.value.sortOrder === 'descending' ? 'desc' : 'asc'
        }
        
        if (dateRange.value?.length === 2) {
          params.startDate = dateRange.value[0]
          params.endDate = dateRange.value[1]
        }

        const response = await axios.get('/api/community/hot-analysis', { params })
        
        if (response.data) {
          hotAnalysis.value.mostActiveUsers = (response.data.mostActiveUsers || []).map(user => ({
            ...user,
            totalActivity: user.postCount + user.commentCount + user.likeCount + user.favoriteCount
          }))
          
          hotAnalysis.value.interactionTrend = response.data.interactionTrend || {
            peakHours: [],
            weeklyPattern: []
          }
          
          hotAnalysis.value.popularTags = response.data.popularTags || []
          
          hotAnalysis.value.pagination.total = response.data.totalItems || 0
          hotAnalysis.value.pagination.currentPage = response.data.currentPage || 1
          hotAnalysis.value.pagination.pageSize = response.data.pageSize || 10
        }
        
        // 渲染每周互动模式图表
        if (weeklyPatternChart) {
          const days = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
          const weeklyData = hotAnalysis.value.interactionTrend.weeklyPattern || Array(7).fill(0)
          
          weeklyPatternChart.setOption({
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'shadow'
              }
            },
            xAxis: {
              type: 'category',
              data: days,
              axisLabel: {
                interval: 0
              }
            },
            yAxis: {
              type: 'value',
              name: '互动量'
            },
            series: [{
              data: weeklyData,
              type: 'bar',
              itemStyle: {
                color: function(params) {
                  return params.dataIndex >= 5 ? '#91CC75' : '#5470C6'
                }
              },
              showBackground: true,
              backgroundStyle: {
                color: 'rgba(180, 180, 180, 0.2)'
              }
            }]
          }, true)
        }
      } catch (error) {
        console.error('获取热门分析数据失败:', error)
        ElMessage.error('获取热门分析数据失败')
      } finally {
        hotAnalysis.value.loading = false
      }
    }

    // 获取热门内容数据
    const fetchHotContent = async () => {
      hotContent.value.loading = true;
      try {
        const params = {
          page: hotContent.value.pagination.currentPage,
          pageSize: hotContent.value.pagination.pageSize,
          timeRange: hotContent.value.timeRange === 'all' ? null : hotContent.value.timeRange,
          sort: 'hotScore',      // 按热度排序
          order: 'desc'         // 降序排列
        };

        const response = await axios.get('/hot-post/list', { params });
        const responseData = response.data.data || {};
        
        hotContent.value.posts = responseData.list || [];
        hotContent.value.pagination.total = responseData.total || 0;
        
        // 获取每个帖子的详细分数信息
        const scorePromises = hotContent.value.posts.map(post => 
          axios.get(`/hot-post/score/${post.postId}`)
            .then(res => {
              post.hotScore = res.data.hotScore || 0;
              post.commentCount = res.data.commentCount || 0;
              post.likeCount = res.data.likeCount || 0;
              post.favoriteCount = res.data.favoriteCount || 0;
              post.tag = res.data.type || '';
              post.createdAt = res.data.createdAt;
              return post;
            })
            .catch(() => {
              post.hotScore = 0;
              post.commentCount = 0;
              post.likeCount = 0;
              post.favoriteCount = 0;
              post.tag = '';
              post.createdAt = '';
              return post;
            })
        );
        
        await Promise.all(scorePromises);
      } catch (error) {
        console.error('获取热门内容失败:', error);
        ElMessage.error('获取热门内容失败');
      } finally {
        hotContent.value.loading = false;
      }
    };

    // 获取图表数据
    const fetchChartData = async () => {
      try {
        let url = '/api/community/analysis'
        if (dateRange.value && dateRange.value.length === 2) {
          const [startDate, endDate] = dateRange.value
          url += `?startDate=${startDate}&endDate=${endDate}`
        }

        const response = await axios.get(url)
        const data = response.data
        
        // 渲染趋势图
        if (trendChart) {
          const trendData = data.interactionTrends || []
          const dates = trendData.map(item => item.date)
          const postCounts = trendData.map(item => item.postCount || 0)
          const commentCounts = trendData.map(item => item.commentCount || 0)
          const likeCounts = trendData.map(item => item.likeCount || 0)
          const favoriteCounts = trendData.map(item => item.favoriteCount || 0)
          
          const option = {
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'cross',
                label: {
                  backgroundColor: '#6a7985'
                }
              }
            },
            legend: {
              data: ['发帖量', '评论数', '点赞数', '收藏数']
            },
            grid: {
              left: '3%',
              right: '4%',
              bottom: '3%',
              containLabel: true
            },
            xAxis: {
              type: 'category',
              boundaryGap: false,
              data: dates
            },
            yAxis: {
              type: 'value'
            },
            series: [
              {
                name: '发帖量',
                type: 'line',
                smooth: true,
                symbol: 'circle',
                symbolSize: 8,
                itemStyle: {
                  color: '#5470C6'
                },
                lineStyle: {
                  width: 3
                },
                data: postCounts
              },
              {
                name: '评论数',
                type: 'line',
                smooth: true,
                symbol: 'circle',
                symbolSize: 8,
                itemStyle: {
                  color: '#91CC75'
                },
                lineStyle: {
                  width: 3
                },
                data: commentCounts
              },
              {
                name: '点赞数',
                type: 'line',
                smooth: true,
                symbol: 'circle',
                symbolSize: 8,
                itemStyle: {
                  color: '#FAC858'
                },
                lineStyle: {
                  width: 3
                },
                areaStyle: {
                  color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                    {
                      offset: 0,
                      color: 'rgba(250, 200, 88, 0.5)'
                    },
                    {
                      offset: 1,
                      color: 'rgba(250, 200, 88, 0.1)'
                    }
                  ])
                },
                data: likeCounts
              },
              {
                name: '收藏数',
                type: 'line',
                smooth: true,
                symbol: 'circle',
                symbolSize: 8,
                itemStyle: {
                  color: '#EE6666'
                },
                lineStyle: {
                  width: 3
                },
                data: favoriteCounts
              }
            ]
          }
      
          // 设置空数据时的提示
          if (trendData.length === 0) {
            option.graphic = {
              type: 'text',
              left: 'center',
              top: 'middle',
              silent: true,
              invisible: false,
              style: {
                fill: '#999',
                text: '暂无数据',
                fontSize: '16px'
              }
            }
          }
          
          trendChart.setOption(option, true)
        }
        
        // 渲染类型分布图
        if (typeChart) {
          const typeData = data.postTypeDistributions || []
          
          typeChart.setOption({
            tooltip: {
              trigger: 'item',
              formatter: '{a} <br/>{b}: {c} ({d}%)'
            },
            legend: {
              orient: 'vertical',
              left: 'left',
            },
            series: [
              {
                name: '帖子类型分布',
                type: 'pie',
                radius: '50%',
                data: typeData.map(item => ({
                  value: item.count,
                  name: item.postType,
                  percentage: item.percentage
                })),
                emphasis: {
                  itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                },
                label: {
                  formatter: '{b}: {c} ({d}%)'
                }
              }
            ]
          }, true)
        }
      } catch (error) {
        console.error('获取图表数据失败:', error)
        ElMessage.error('获取图表数据失败')
      }
    }

    // 初始化数据
    const fetchData = async () => {
      try {
        await fetchCoreMetrics()
        
        if (activeTab.value === 'trend') {
          await fetchChartData()
        } else if (activeTab.value === 'hot') {
          await fetchHotAnalysis()
        } else if (activeTab.value === 'content') {
          await fetchHotContent()
        }
      } catch (error) {
        console.error('获取社区数据失败:', error)
        ElMessage.error('获取数据失败')
      }
    }

    // ==================== 分页处理 ====================
    const handlePageSizeChange = (newSize) => {
      hotAnalysis.value.pagination.pageSize = newSize
      hotAnalysis.value.pagination.currentPage = 1
      fetchHotAnalysis()
    }

    const handlePageChange = (newPage) => {
      hotAnalysis.value.pagination.currentPage = newPage
      fetchHotAnalysis()
    }

    const handleHotContentPageSizeChange = (newSize) => {
      hotContent.value.pagination.pageSize = newSize
      hotContent.value.pagination.currentPage = 1
      fetchHotContent()
    }

    const handleHotContentPageChange = (newPage) => {
      hotContent.value.pagination.currentPage = newPage
      fetchHotContent()
    }

    // ==================== 图表初始化 ====================
    const initCharts = () => {
      trendChart = echarts.init(document.getElementById('trendChart'))
      typeChart = echarts.init(document.getElementById('typeChart'))
      weeklyPatternChart = echarts.init(document.getElementById('weeklyPatternChart'))
      
      // 窗口大小变化时重新调整图表大小
      window.addEventListener('resize', function() {
        trendChart?.resize()
        typeChart?.resize()
        weeklyPatternChart?.resize()
      })
    }

    // ==================== 生命周期 ====================
    onMounted(() => {
      initCharts()
      // 确保首次加载时按正确的排序获取数据
      hotAnalysis.value.sortProp = 'totalActivity'
      hotAnalysis.value.sortOrder = 'descending'
      fetchData()
    })

    return {
      dateRange,
      selectedType,
      searchText,
      metrics,
      hotAnalysis,
      hotContent,
      activeTab,
      formatNumber,
      formatDate,
      handleDateChange,
      handleTabChange,
      getTagType,
      getScoreType,
      getActivityType,
      handleSortChange,
      handlePageSizeChange,
      handlePageChange,
      handleHotContentPageSizeChange,
      handleHotContentPageChange,
      handleTimeRangeChange
    }
  }
}
</script>

<style scoped lang="scss">
.community-analysis-container {
  padding: 24px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 60px);
}

.page-title {
  color: #303133;
  margin-bottom: 24px;
  font-size: 24px;
  font-weight: 500;
  display: flex;
  align-items: center;
  
  &::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 18px;
    background: #409eff;
    margin-right: 12px;
    border-radius: 2px;
  }
}

.filter-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  align-items: center;
  background: #fff;
  padding: 16px 20px;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.community-core-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  position: relative;
  transition: all 0.3s ease;
  border-left: 4px solid #409eff;
  
  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  }
}

.metric-title {
  font-size: 14px;
  color: #909399;
  margin-bottom: 12px;
}

.metric-value {
  font-size: 28px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 8px;
}

.metric-subtitle {
  font-size: 12px;
  color: #c0c4cc;
  position: absolute;
  bottom: 12px;
  left: 20px;
  right: 20px;
}

.analysis-nav {
  background: #fff;
  border-radius: 8px;
  padding: 0 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

:deep(.el-tabs__header) {
  margin: 0;
}

:deep(.el-tabs__nav-wrap::after) {
  height: 1px;
}

.chart-container {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  min-height: 500px;
}

.chart-area h3 {
  margin-top: 0;
  margin-bottom: 20px;
  color: #303133;
  font-size: 18px;
  font-weight: 500;
  padding-bottom: 12px;
  border-bottom: 1px solid #ebeef5;
}

#trendChart, #typeChart, #weeklyPatternChart {
  margin-bottom: 30px;
}

.hot-content-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.hot-content-filter {
  display: flex;
  align-items: center;
  padding: 10px 0;
}

.hot-content-list {
  flex: 1;
}

.post-content {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.5;
  color: #606266;
}

.hot-analysis-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.hot-analysis-section {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  
  h4 {
    margin-top: 0;
    margin-bottom: 16px;
    color: #606266;
    font-size: 16px;
    font-weight: 500;
  }
}

.peak-hours {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.peak-hour-tag {
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 16px;
}

.popular-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.popular-tag {
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 16px;
}

.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}

.user-rank-filter {
  display: flex;
  justify-content: flex-end;
}

/* 美化表格样式 */
:deep(.el-table) {
  border-radius: 8px;
  overflow: hidden;
  
  th {
    background-color: #f5f7fa !important;
    color: #606266;
    font-weight: 500;
  }
  
  .el-table__row:hover {
    td {
      background-color: #f5f7fa !important;
    }
  }
}

/* 美化分页样式 */
:deep(.el-pagination) {
  .btn-prev, .btn-next, .number {
    border-radius: 6px;
    min-width: 32px;
    height: 32px;
    line-height: 32px;
  }
  
  .number.active {
    background-color: #409eff;
    color: #fff;
  }
}

/* 美化标签样式 */
:deep(.el-tag) {
  border-radius: 12px;
  padding: 0 10px;
  height: 26px;
  line-height: 24px;
  
  &.el-tag--large {
    height: 32px;
    line-height: 30px;
    font-size: 14px;
  }
}
</style>